import {
	getuserDataApi
} from "@/api/myinter.js"
import {
	mywalletApi
} from "@/api/home.js"

export default {
	namespaced: 'my',
	state: {
		balance: null, //余额
		totalPoints: null, //积分
		inviteCode: null, //邀请码
		userLevel: null, //用户等级
		imgUrl: null, //头像
		parentPhone: null,
		phone: null,
		nickname: '',
		couponsCount: null,
		vipLevel: null,
		vipDescription:null,
		realNameAuth: false,
		balanceTwo:0,//余额
		todayAmount:0,//今日收益
		totalAmount:0,//累计收益收益
		realNameAuthTwo:Boolean,//判断是否有实名认证
		openBank:Boolean//是否开放提现
	},
	mutations: {
		changeData(state, res) {
			state.balance = res.data.data.balance
			state.inviteCode = res.data.data.inviteCode
			state.userLevel = res.data.data.userLevel
			state.couponsCount = res.data.data.couponsCount
			state.totalPoints = res.data.data.frozePoints + res.data.data.points
			state.imgUrl = res.data.data.imgUrl
			state.parentPhone = res.data.data.parentPhone
			state.phone = res.data.data.phone
			state.nickname = res.data.data.nickname
			state.vipLevel = res.data.data.vipLevel
			state.vipDescription = res.data.data.vipDescription
			state.realNameAuth = res.data.data.realNameAuth
			state.openBank=res.data.data.openBank
		},
		getMyWallet(state, res) {
			state.balanceTwo = res.data.data.balance
			state.todayAmount = res.data.data.todayAmount
			state.totalAmount = res.data.data.totalAmount
			state.realNameAuthTwo = res.data.data.realNameAuth
		}
	},
	actions: {
		async getUserData(context, value) {
			uni.showLoading({
				title: "正在加载中...."
			})
			const res = await getuserDataApi({})
			if (res.statusCode === 200) {
				uni.hideLoading()
				context.commit('changeData', res);
			}
		},
		// 获取个人数据
		async getPersonalData(context, value) {
			uni.showLoading({
				title: "正在加载中...."
			})
			const res = await mywalletApi({})
			if (res.statusCode === 200) {
				uni.hideLoading()
				context.commit('getMyWallet', res);
			}
		}
	}
}
